# -*- coding: utf-8 -*-
import  time
def show_info():
    print('输入提示数字，执行相应的操作:0.退出  1.查看登录日志')

# 记录日志
def write_logininfo(username):
    with open('log.txt', 'a', encoding='utf-8') as file:
        s=f'用户名{username},登录时间:{time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))}'
        file.write(s)
        file.write('\n')

def read_loginfo():
    with open('log.txt', 'r', encoding='utf-8') as file:
        while True:
            line=file.readline()
            if line=='':
                break
            else:
                print(line)
if __name__ == '__main__':
    # write_logininfo('admin')
    username=input('请输入用户名')
    pwd=input('请输入密码')
    if username =='admin' and pwd =='abc':
        print('登陆成功')
        write_logininfo(username)
        show_info()
        num=eval(input('要操作数字'))
        while True:
            if num==0:
                break
            elif num==1:
                print('查看登录日志:')
                read_loginfo()
                show_info()
            else:
                print('对不起，你输入有误')
                show_info()
            num=eval(input('请输入数字'))
    else:
        print('不正确')